1 /***
2 * QuiltRunner
3 *
4 * Runs JUnit tests with Coverage.
5 */
6
7 package junit.quilt.runner;
8
9 import junit.framework.*;
10 import junit.runner.*;
11
12 import java.io.File;
13
14 import java.util.List;
15 import java.util.Iterator;
16 import java.util.Properties;
17
18 import junit.quilt.reports.*;
19 import junit.quilt.framework.*;
20
21 public abstract class QuiltRunner
22 extends BaseTestRunner
23 {
24 private QuiltRegistry registry = null;
25
26 private class QRunner
27 extends Thread
28 {
29 private Test t = null;
30 private TestResult r = null;
31
32 public QRunner( Test t, TestResult r ) {
33 this.t = t;
34 this.r = r;
35 }
36
37 public void run() {
38 t.run( r );
39 }
40 }
41
42 public QuiltRunner( Class registryClass,
43 ClassLoader parent,
44 List urls, // LIST( URL )
45 List packages ) // LIST( String )
46 throws Exception
47 {
48 super();
49
50 this.registry =
51 (QuiltRegistry) registryClass.newInstance();
52
53 registry.setParentClassLoader( parent );
54
55 registry.setPackages( packages );
56 registry.setPaths( urls );
57 }
58
59 public QuiltRegistry getRegistry() {
60 return registry;
61 }
62
63 public TestSuiteLoader getLoader() {
64 if (registry != null) {
65 return new QuiltSuiteLoader(registry.getInstClassLoader());
66 } else {
67 return new ReloadingTestSuiteLoader();
68 }
69 }
70
71 /***
72 * executeTest - Execute the test given a file name.
73 */
74 public TestResult executeTest( String testName ) {
75 try {
76 Test suite = getTest( testName );
77 TestResult result = new TestResult();
78
79 result.addListener( this );
80
81 QRunner q = new QRunner( suite, result );
82
83 q.setContextClassLoader( getRegistry().getInstClassLoader() );
84
85 if (suite == null) {
86 System.err.println("WARNING: Test " + testName +
87 " not found.");
88 } else {
89 // suite.run( result );
90 q.run();
91 }
92
93 q.join();
94
95 return result;
96 } catch (Exception e) {
97 e.printStackTrace();
98 return null;
99 }
100 }
101 }
This page was automatically generated by Maven